//
//  ClassifiedInquiryView.m
//  Runone
//
//  Created by runone02 on 16/8/22.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "ClassifiedInquiryView.h"
#import "Masonry.h"

@implementation ClassifiedInquiryView
#pragma  mark - lazy loadd
- (UILabel *)roadTypeLabel
{
    if (!_transTypeLabel) {
        UILabel* label = [[UILabel alloc]init];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor blackColor];
        label.font = [UIFont systemFontOfSize:15.0f];
        label.text = @"道路类型";
        _roadTypeLabel = label;    }
    return _roadTypeLabel;
}
- (UILabel *)leftKLabel
{
    if (!_leftKLabel) {
        UILabel* label = [[UILabel alloc]init];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor blackColor];
        label.font = [UIFont systemFontOfSize:15.0f];
        label.text = @"K";
        _leftKLabel = label;    }
    return _leftKLabel;
}

- (UILabel *)rightKLabel
{
    if (!_rightKLabel) {
        UILabel* label = [[UILabel alloc]init];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor blackColor];
        label.font = [UIFont systemFontOfSize:15.0f];
        label.text = @"K";
        _rightKLabel = label;    }
    return _rightKLabel;
}

- (UIButton *)roadTypeBtn
{
    if (!_roadTypeBtn) {
         UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"请输入道路类型" forState:UIControlStateNormal];
        button.tag = 11;
        button.backgroundColor = [UIColor lightGrayColor];
        button.titleLabel.font = [UIFont systemFontOfSize:15];
        button.titleLabel.textAlignment = NSTextAlignmentLeft;
        [button addTarget:self action:@selector(roadTypeBtnClick:) forControlEvents:UIControlEventTouchDown];
        _roadTypeBtn = button;
    }
    return _roadTypeBtn;
}

- (UILabel *)transTypeLabel
{
    if (!_transTypeLabel) {
        UILabel* label = [[UILabel alloc]init];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor blackColor];
        label.font = [UIFont systemFontOfSize:15.0f];
        label.text = @"车辆类型";
        _transTypeLabel = label;
    }
    return _transTypeLabel;
}

- (UIButton *)transTypeBtn
{
    if (!_transTypeBtn) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 12;
        [button setTitle:@"请输入车辆类型" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:15];
        button.titleLabel.textAlignment = NSTextAlignmentLeft;
        button.backgroundColor = [UIColor lightGrayColor];

        [button addTarget:self action:@selector(transTypebtnClick:) forControlEvents:UIControlEventTouchDown];
        _transTypeBtn = button;
    }
    return _transTypeBtn;
}

- (UILabel *)drivingDirectionsLabel
{
    if (!_drivingDirectionsLabel) {
        UILabel* label = [[UILabel alloc]init];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor blackColor];
        label.font = [UIFont systemFontOfSize:15.0f];
        label.text = @"行车方向";
        _drivingDirectionsLabel = label;
    }
    return _drivingDirectionsLabel;
}

- (UIButton *)drivingDirectionsBtn
{
    if (!_drivingDirectionsBtn) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 13;
        [button setTitle:@"请输入行车方向" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:15];
        button.titleLabel.textAlignment = NSTextAlignmentLeft;
        button.backgroundColor = [UIColor lightGrayColor];
        
        [button addTarget:self action:@selector(drivingDirectionsBtnClick:) forControlEvents:UIControlEventTouchDown];
        _drivingDirectionsBtn = button;
    }
    return _drivingDirectionsBtn;
}

- (UILabel *)stakeNOLabel
{
    if (!_stakeNOLabel) {
        UILabel* label = [[UILabel alloc]init];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor blackColor];
        label.font = [UIFont systemFontOfSize:15.0f];
        label.textAlignment = NSTextAlignmentRight;
        label.text = @"桩号";
        _stakeNOLabel = label;
    }
    return _stakeNOLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = [UIColor blackColor];
        _lineView = view;
    }
    return _lineView;
}



- (UITextField *)leftField {
    if (!_leftField) {
        UITextField *field = [[UITextField alloc] init];
        field.borderStyle  = UITextBorderStyleBezel;
        field.textColor    = [UIColor lightGrayColor];
        field.keyboardType = UIKeyboardTypeNumberPad;
        _leftField = field;
    }
    return  _leftField;
}

- (UITextField *)rightField {
    if (!_rightField) {
        UITextField *field = [[UITextField alloc] init];
        field.borderStyle  = UITextBorderStyleBezel;
        field.textColor    = [UIColor lightGrayColor];
        field.keyboardType = UIKeyboardTypeNumberPad;
        _rightField = field;
    }
    return  _rightField;
}

- (UIButton *)cancleBtn
{
    if (!_cancleBtn) {
        UIButton *button = [[UIButton alloc]init];
        button.tag = 14;
        [button addTarget:self action:@selector(cancleButtonClick:) forControlEvents:UIControlEventTouchDown];
        [button setBackgroundColor:[UIColor lightGrayColor]];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitle:@"取消" forState:UIControlStateNormal];
        _cancleBtn = button;
    }
    return _cancleBtn;
}

- (UIButton *)confirmBtn
{
    if (!_confirmBtn) {
        UIButton *button = [[UIButton alloc]init];
        button.tag = 15;
        [button addTarget:self action:@selector(confirmButtonClick:) forControlEvents:UIControlEventTouchDown];
        [button setBackgroundColor:[UIColor lightGrayColor]];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitle:@"确定" forState:UIControlStateNormal];
        _confirmBtn = button;
    }
    return _confirmBtn;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame] ) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    
    [self addSubview:self.roadTypeLabel];
    [self addSubview:self.roadTypeBtn];
    [self addSubview:self.transTypeLabel];
    [self addSubview:self.transTypeBtn];
    [self addSubview:self.drivingDirectionsLabel];
    [self addSubview:self.drivingDirectionsBtn];
    [self addSubview:self.stakeNOLabel];
    [self addSubview:self.leftField];// 左
    [self addSubview:self.lineView];
    [self addSubview:self.rightField];// 右
    [self addSubview:self.cancleBtn];
    [self addSubview:self.confirmBtn];
    [self addSubview:self.leftKLabel];//左边K
    [self addSubview:self.rightKLabel];//右边K
    
    __weak typeof(self) weakSelf = self;
    
    [self.roadTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_top).with.offset(10);
        make.left.equalTo(weakSelf.mas_left).with.offset(10);
    }];
    
    [self.roadTypeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_top).with.offset(10);
        make.left.equalTo(weakSelf.roadTypeLabel.mas_right).with.offset(10);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(20);
    }];
    
    [self.transTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.roadTypeLabel.mas_bottom).with.offset(10);
        make.left.equalTo(weakSelf.mas_left).with.offset(10);
    }];
    
    [self.transTypeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.roadTypeLabel.mas_bottom).with.offset(10);
        make.left.equalTo(weakSelf.transTypeLabel.mas_right).with.offset(10);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(20);
    }];
    
    [self.drivingDirectionsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.transTypeLabel.mas_bottom).with.offset(10);
        make.left.equalTo(weakSelf.mas_left).with.offset(10);
    }];

    [self.drivingDirectionsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.transTypeLabel.mas_bottom).with.offset(10);
        make.left.equalTo(weakSelf.drivingDirectionsLabel.mas_right).with.offset(10);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(20);
    }];
    
    [self.stakeNOLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.drivingDirectionsLabel.mas_bottom).with.offset(10);
        make.left.equalTo(weakSelf.mas_left).with.offset(10);
        make.right.equalTo(weakSelf.drivingDirectionsLabel.mas_right);
    }];
    
    [self.leftKLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.stakeNOLabel.mas_top);
        make.left.equalTo(weakSelf.stakeNOLabel.mas_right).with.offset(10);
    }];
    
    [self.leftField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.drivingDirectionsLabel.mas_bottom).with.offset(10);
        make.left.equalTo(weakSelf.leftKLabel.mas_right);
        make.size.mas_equalTo(CGSizeMake(70, 25));
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.leftField.mas_centerY);
        make.left.equalTo(weakSelf.leftField.mas_right).with.offset(5);
        make.size.mas_equalTo(CGSizeMake(30, 1));
    }];
    
    [self.rightKLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.stakeNOLabel.mas_top);
        make.left.equalTo(weakSelf.lineView.mas_right).with.offset(5);
    }];
    
    [self.rightField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.rightKLabel.mas_right).with.offset(5);
        make.top.equalTo(weakSelf.drivingDirectionsLabel.mas_bottom).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(70, 25));
    }];
    
    [self.cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.stakeNOLabel.mas_bottom).with.offset(20);
        make.left.equalTo(weakSelf.mas_left).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.cancleBtn.mas_centerY);
        make.right.equalTo(weakSelf.mas_right).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
}

- (void)roadTypeBtnClick:(UIButton *)btn {
    NSLog(@"1");
    if (self.btnClick) {
        self.btnClick(btn);
    }
}

- (void)transTypebtnClick:(UIButton *)btn {
    NSLog(@"2");
    if (self.btnClick) {
        self.btnClick(btn);
    }
}

- (void)drivingDirectionsBtnClick:(UIButton *)btn {
    if (self.btnClick) {
        self.btnClick(btn);
    }
}

- (void)cancleButtonClick:(UIButton *)btn {
    NSLog(@".......");
    if ((self.btnClick)) {
        self.btnClick(btn);
    }
}

- (void)confirmButtonClick:(UIButton *)btn {
     NSLog(@".......");
    if (self.btnClick) {
        self.btnClick(btn);
    }
   
}

@end
